<template>
	<view>
		<view class="header">
			<view class="uni-px-5 uni-pb-5" style="width: 100%;background-color: #FFFFFF;">
				<uni-data-select v-model="value"  @change="change" :localdata="range" placeholder="请先选择工厂"></uni-data-select>
			</view>
			<view class="uni-px-5 uni-pb-5" style="width: 100%;background-color: #FFFFFF;display: flex;flex-direction: row;margin-top: 10rpx;">
				<input v-model="searchValue"  confirm-type="search"  @confirm="onInput" class="input" type="text"
				 placeholder="搜索仓库" style="height: 60rpx;width: 650rpx;"/>
				 <view class='cuIcon-search' style="padding-top: 5rpx;width: 40px;padding-left: 30rpx;" @click="onInput"></view>
			</view>
		</view>
		<form id="root" @submit="formSubmit">
			<view class="title">
				<view class="num">仓库编码</view>

				<view class="name">仓库名称</view>
			</view>
			<view style="margin-bottom: 100rpx;">
				<view class="con-list">
					<radio-group class="radio-group" @change="radioChange">
						<label  class="contentd" v-for="(item,index) in listLgortOptions" :key="index">
							<view class="kuang">
								<radio :value="item.operationCode" :checked="item.checked" />
							</view>
							<view class="num-value">{{item.operationCode}}</view>
							<view class="name-value">{{item.operationName}}</view>
						</label>
					</radio-group>
				</view>
			</view>
			<view style="height: 50rpx;background-color: #FFFFFF;"></view>
			<view>
				<button class="fott" form-type="submit" >确定</button>
			</view>

		</form>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				bgColor: 'bg-green',
				gongxuList: [],
				werksOptions:[],
				listLgortOptions:[],
				gongxuPickerList: ['请先选择工厂'],
				indexGongxu:'',
				order:{},
				value: '',
				range: [],
				selectedFactory:{},
				selectedStore:{},
				searchValue: '',
				werk:''
			}
		},
		onShow() {
			this.getFactory()
			this.exit = uni.getStorageSync('rewerks')
			this.change(this.exit.value)
		},
		methods: {
			getFactory(){
				let url = '/dcloud/mm/goodsReceipt/main/listWerksOptions'
				this.$http.post(url, {
					
				}).then(res => {
					if (res && res.data.result) {
						this.range = res.data.result;
					}
				}).catch(err => {
					console.log(err);
				});
			},
			change(e) {
				
				  if(e==null || e==''){
					return;
				  } 
				//设置选中的工厂
				if(this.exit.value == e){
					this.selectedFactory = this.exit
					uni.setStorageSync('rewerks', this.exit);
				}else{
					this.range.forEach(v=>{
						if(v.value == e){
							this.selectedFactory = v;
							uni.setStorageSync('rewerks', v);
						}
					});
				}
				  
					let url = '/dcloud/mm/goodsIssue/main/listLgortOptions'
					this.$http.post(url+ "?werks=" + e, {
						
					}).then(res => {
						this.werk = e
						if (res && res.data.result) {
							this.listLgortOptions = [];
							res.data.result.forEach(v=>{
								var template = {operationCode:v.value,operationName:v.text};
								this.listLgortOptions.push(template);
							});
							
						}
					}).catch(err => {
						console.log(err);
					});
			},
			radioChange: function(e) {
				 const items = this.listLgortOptions
				    for (let i = 0, len = items.length; i < len; i++) {
				      items[i].checked = items[i].operationCode === e.detail.value
					  if(items[i].operationCode === e.detail.value){
						  this.order = items[i];
					  }
				    }
				this.listLgortOptions = items;
				// 设置选中的仓库
				this.selectedStore = this.order;
				uni.setStorageSync('restore', this.selectedStore);
			},
			formSubmit:function(e){//返回上一层
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.receFactory = this.selectedFactory;
				prevPage.$vm.receStore = this.selectedStore;
				uni.navigateBack({
					delta:1
				})
			},
			onInput(e){
				let url = '/dcloud/mm/goodsReceipt/main/listLgortOptions'
				this.$http.post(url+ "?werks=" + this.werk + '&' +"lgobe=" + this.searchValue).then(res => {
					if (res && res.data.result) {
						this.listLgortOptions = [];
						res.data.result.forEach(v=>{
							var template = {operationCode:v.value,operationName:v.text};
							this.listLgortOptions.push(template);
						});
						
					}
				}).catch(err => {
					console.log(err);
				});
				this.searchValue = ''
			}
		}
	}
</script>

<style lang="scss">
	.uni-list-cell {
		justify-content: flex-start
	}
	.con-list {
		min-height: 884upx;
		background-color: #FFFFFF;
		margin-bottom: 20rpx;
	}
	.title {
		display: flex;
		flex-direction: row;
		width: 100%;
		background-color: #FFFFFF;
		height: 100rpx;
		font-size: 28px;
	}

	.contentd {
		display: flex;
		flex-direction: row
	}

	.num {
		width: 20%;
		text-align: center;
		line-height: 100rpx;
		margin-left: 100rpx;
	}

	.name {
		width: 40%;
		line-height: 100rpx;
		text-align: center;
		margin-left: 50rpx;
	}

	.num-value {
		width: 15%;
		text-align: center;
		line-height: 100rpx;

	}

	.name-value {
		width: 75%;
		line-height: 100rpx;
		text-align: center;
	}
	.kuang {
		width: 10%;
		margin-left: 30rpx;
		line-height: 100rpx;
		text-align: center;
	}

	.fott {
		  border-radius:0;
		  position: fixed;
		  bottom: 0;
		  width: 100%;
		  justify-content: center;
	}
	.header {
		display: flex;
		flex-direction: column;
		padding: 10px 15px;
		align-items: center;
		/* background-color: #b6bbc3; */
		background-image: linear-gradient(#34A4DF, #34A4DF, #2bace7);
	}

	.icon {
		display: flex;
		flex-direction: column;
		justify-content: center;
		margin-left: 10px;
	}
</style>
